package top.zuli.package01.class13;

/**
 * 主线程和子线程同时打印1-100
 */
public class ThreadDemo1 extends Thread{
    @Override
    public void run() {
        for (int i = 1; i <=100 ; i++) {
            //让程序运行慢点，停留100毫秒后在执行
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //this.getName()获得线程名字
            System.out.println(this.getName()+":"+i);
        }
    }

    public static void main(String[] args) {
        //1.创建子线程
        Thread thread = new ThreadDemo1();
        //2.运行子线程中的run方法代码
        thread.start();
        //3.主线程运行代码
        for(int i=1;i<=100;i++){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(i);
        }
    }
}
